package jgl.vajra.driver.widget.dialogfragment;

import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;

import jgl.vajra.driver.R;
import jgl.vajra.driver.databinding.DialogNetLoadingBinding;
import jgl.vajra.driver.widget.bean.LoadingDialogConfigBean;
import jgl.vajra.driver.widget.interfaces.DialogFragmentStatesListener;

/**
 * @Author zhangshuqi
 * @CreateTime 2018/3/21
 * @Describe 访问网络或者数据库 loading处理
 */

public class LoadingDialogFragment extends BaseDialogFragment<DialogNetLoadingBinding> {

    private LoadingDialogConfigBean bean;
    private String loadingText = "加载中,请稍后";
    private DialogFragmentStatesListener mDialogFragmentStatesListener;
    private boolean isUserBlur = true;

    @Override
    public void initView(Context context, View rootView, AttributeSet attrs) {

    }

    @Override
    public void initData(Context context) {
        bean = new LoadingDialogConfigBean();
        bean.text = loadingText;
        mBinding.setData(bean);
    }

    @Override
    public void initEvent(Context context) {
    }

    @Override
    public boolean isUseBlur() {
        return false;
    }


    @Override
    public int getLayoutRes() {
        return R.layout.dialog_net_loading;
    }

    @Override
    public int setDisplayAnimation() {
        return TYPE_LEFT;
    }

    @Override
    public boolean getCancelOutside() {
        return true;
    }

    @Override
    public boolean isHeightMatchParent() {
        return true;
    }

    public void setLoadingText(String text) {
        if (!TextUtils.isEmpty(text))
            loadingText = text;
    }

    public void setCancelOutside(boolean f) {
        //bean.setCancel(f);
        setCancelable(f);
    }

    public void setUseBlur(boolean f) {
        this.isUserBlur = f;
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        if (mDialogFragmentStatesListener != null) mDialogFragmentStatesListener.onDismiss(dialog);
    }

    public void setDialogFragmentStatesListener(DialogFragmentStatesListener dialogInterface) {
        this.mDialogFragmentStatesListener = dialogInterface;
    }


}
